package com.kenai.jbosh;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;

final class ZLIBCodec
{
  private static final int BUFFER_SIZE = 512;

  public static byte[] decode(byte[] paramArrayOfByte)
    throws IOException
  {
    InflaterInputStream localInflaterInputStream;
    ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(paramArrayOfByte);
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    Object localObject1 = null;
    try
    {
      localInflaterInputStream = new InflaterInputStream(localByteArrayInputStream);
    }
    finally
    {
      try
      {
        int i;
        byte[] arrayOfByte1 = new byte[512];
        do
        {
          i = localInflaterInputStream.read(arrayOfByte1);
          if (i > 0)
            localByteArrayOutputStream.write(arrayOfByte1, 0, i);
        }
        while (i >= 0);
        byte[] arrayOfByte2 = localByteArrayOutputStream.toByteArray();
        localInflaterInputStream.close();
        localByteArrayOutputStream.close();
        return arrayOfByte2;
        localObject2 = finally;
        localObject1.close();
        localByteArrayOutputStream.close();
        throw localObject2;
      }
      finally
      {
        localObject1 = localInflaterInputStream;
      }
    }
  }

  public static byte[] encode(byte[] paramArrayOfByte)
    throws IOException
  {
    DeflaterOutputStream localDeflaterOutputStream;
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    Object localObject1 = null;
    try
    {
      localDeflaterOutputStream = new DeflaterOutputStream(localByteArrayOutputStream);
    }
    finally
    {
      try
      {
        localDeflaterOutputStream.write(paramArrayOfByte);
        localDeflaterOutputStream.close();
        localByteArrayOutputStream.close();
        byte[] arrayOfByte = localByteArrayOutputStream.toByteArray();
        localDeflaterOutputStream.close();
        localByteArrayOutputStream.close();
        return arrayOfByte;
        localObject2 = finally;
        localObject1.close();
        localByteArrayOutputStream.close();
        throw localObject2;
      }
      finally
      {
        localObject1 = localDeflaterOutputStream;
      }
    }
  }

  public static String getID()
  {
    return "deflate";
  }
}